// pages/zhaoping/zhaoping.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

    xueshen: true,
    txtlist: [],
    POST_WORK: '', //岗位
    STUDENT_PHONE: '', //手机号
    POST_SALARY: '', //期望薪资
    POST_NAME: '', //姓名
    wangdian: [
      // {
      //   id: 1,
      //   wangname: "县营业网点"
      // },
      {
        id: 1,
        wangname: "商州",
        wangnamea: [{
            id: 2,
            wangname: "商州西新街邮局"
          },
          {
            id: 3,
            wangname: "商州名人街邮局"
          },
          {
            id: 4,
            wangname: "商州东郊校邮局"
          },
          {
            id: 5,
            wangname: "商州夜村邮局"
          },
          {
            id: 6,
            wangname: "商州白杨店邮局"
          },
          {
            id: 7,
            wangname: "商州杨斜邮局"
          },
          {
            id: 8,
            wangname: "商州金陵寺邮局"
          },
          {
            id: 9,
            wangname: "商州黑山邮局"
          },
          {
            id: 10,
            wangname: "商州板桥邮局"
          },
          {
            id: 11,
            wangname: "商州腰市邮局"
          },
          {
            id: 12,
            wangname: "商州大荆邮局"
          },
          {
            id: 13,
            wangname: "商州沙河子邮局"
          },
          {
            id: 14,
            wangname: "商州黑龙口邮局"
          },
        ],



      },

      {
        id: 15,
        wangname: "洛南",
        wangnamea: [{
            id: 16,
            wangname: "洛南新西街邮局"
          },
          {
            id: 16,
            wangname: "洛南石门邮局"
          },
          {
            id: 17,
            wangname: "洛南寺耳邮局"
          },
          {
            id: 18,
            wangname: "洛南石坡邮局"
          },
          {
            id: 19,
            wangname: "洛南巡检邮局"
          },
          {
            id: 20,
            wangname: "洛南灵口邮局"
          },
          {
            id: 21,
            wangname: "洛南三要邮局"
          },
          {
            id: 22,
            wangname: "洛南古城邮局"
          },
          {
            id: 23,
            wangname: "洛南景村邮局"
          },
          {
            id: 24,
            wangname: "洛南永丰邮局"
          },
          {
            id: 25,
            wangname: "洛南保安邮局"
          },
        ],
      },
      {
        id: 26,
        wangname: "丹凤",
        wangnamea: [{
            id: 26,
            wangname: "丹凤武关邮局"
          },
          {
            id: 27,
            wangname: "丹凤龙驹寨邮局"
          },
          {
            id: 28,
            wangname: "丹凤广场邮局"
          },
          {
            id: 29,
            wangname: "丹凤棣花邮局"
          },
          {
            id: 30,
            wangname: "丹凤竹林关邮局"
          },
          {
            id: 31,
            wangname: "丹凤商镇邮局"
          },
          {
            id: 32,
            wangname: "丹凤铁峪铺邮局"
          },
          {
            id: 33,
            wangname: "丹凤峦庄邮局"
          },
        ]
      },

      {
        id: 34,
        wangname: "商南",
        wangnamea: [{
            id: 34,
            wangname: "商南长新路邮局"
          },
          {
            id: 35,
            wangname: "商南湘河邮局"
          },
          {
            id: 36,
            wangname: "商南青山邮局"
          },
          {
            id: 37,
            wangname: "商南白玉邮局"
          },
          {
            id: 38,
            wangname: "商南富水邮局"
          },
          {
            id: 39,
            wangname: "商南赵川邮局"
          },
          {
            id: 40,
            wangname: "商南试马邮局"
          },
          {
            id: 41,
            wangname: "商南南街邮局"
          },
        ]
      },
      {
        id: 42,
        wangname: "山阳",
        wangnamea: [{
            id: 42,
            wangname: "山阳城关镇邮局"
          },
          {
            id: 43,
            wangname: "山阳户垣邮局"
          },
          {
            id: 44,
            wangname: "山阳小河邮局"
          },
          {
            id: 67,
            wangname: "山阳丰阳邮局"
          },
          {
            id: 45,
            wangname: "山阳色河邮局"
          },
          {
            id: 46,
            wangname: "山阳宽坪邮局"
          },
          {
            id: 47,
            wangname: "山阳漫川邮局"
          },
          {
            id: 48,
            wangname: "山阳照川邮局"
          },
          {
            id: 49,
            wangname: "山阳中村邮局"
          },
          {
            id: 50,
            wangname: "山阳高坝邮局"
          },
        ]

      },
      {
        id: 51,
        wangname: "镇安",
        wangnamea: [{
            id: 51,
            wangname: "镇安云镇邮局"
          },
          {
            id: 52,
            wangname: "镇安青铜邮局"
          },
          {
            id: 53,
            wangname: "镇安柴坪邮局"
          },
          {
            id: 54,
            wangname: "镇安迎宾路邮局"
          },
          {
            id: 55,
            wangname: "镇安高峰邮局"
          },
          {
            id: 56,
            wangname: "镇安回龙邮局"
          },
          {
            id: 57,
            wangname: "镇安西口邮局"
          },
          {
            id: 58,
            wangname: "镇安米粮邮局"
          },
          {
            id: 59,
            wangname: "镇安大坪邮局"
          },
          {
            id: 60,
            wangname: "镇安永安路邮局"
          },
          {
            id: 61,
            wangname: "镇安永乐邮局"
          },
        ]
      },
      {
        id: 62,
        wangname: "柞水",
        wangnamea: [{
            id: 62,
            wangname: "柞水曹坪邮局"
          },
          {
            id: 63,
            wangname: "柞水凤镇邮局"
          },
          {
            id: 64,
            wangname: "柞水下梁邮局"
          },
          {
            id: 65,
            wangname: "柞水营盘邮局"
          },
          {
            id: 66,
            wangname: "柞水红岩寺邮局"
          },

          {
            id: 68,
            wangname: "柞水霍台邮局"
          },
          {
            id: 69,
            wangname: "柞水北关邮局"
          },
          {
            id: 70,
            wangname: "柞水乾佑街邮局"
          },
        ]
      },

    ], //网点名称
    sheng: [{
        shengnei: '省内'
      },
      {
        shengnei: '省外'
      },
    ],

    xingbie: true,
    nianji: true,

    xinbiexuan: [{
        xinbie: '男'
      },
      {
        xinbie: '女'
      },
    ],

    nianjixuan: [{
        nianji: '16'
      },
      {
        nianji: '17'
      },
      {
        nianji: '18'
      },
      {
        nianji: '19'
      },
      {
        nianji: '20'
      },
      {
        nianji: '21'
      },
      {
        nianji: '22'
      },
      {
        nianji: '23'
      },
      {
        nianji: '24'
      },
      {
        nianji: '25'
      },
      {
        nianji: '26'
      },
      {
        nianji: '27'
      },
      {
        nianji: '28'
      },
      {
        nianji: '29'
      },
      {
        nianji: '30'
      },
      {
        nianji: '31'
      },
      {
        nianji: '32'
      },
      {
        nianji: '33'
      },
      {
        nianji: '34'
      },
      {
        nianji: '35'
      },
      {
        nianji: '36'
      },
      {
        nianji: '37'
      },
      {
        nianji: '38'
      },
      {
        nianji: '39'
      },
      {
        nianji: '40'
      },
      {
        nianji: '41'
      },
      {
        nianji: '42'
      },
      {
        nianji: '43'
      },
      {
        nianji: '44'
      },
      {
        nianji: '45'
      },
      {
        nianji: '46'
      },
      {
        nianji: '47'
      },
      {
        nianji: '48'
      },
      {
        nianji: '49'
      },
      {
        nianji: '50'
      },
      {
        nianji: '51'
      },
      {
        nianji: '52'
      },

      {
        nianji: '53'
      },
      {
        nianji: '54'
      },
      {
        nianji: '55'
      },
      {
        nianji: '56'
      },
      {
        nianji: '57'
      },
      {
        nianji: '58'
      },
      {
        nianji: '59'
      },
      {
        nianji: '60'
      },
      {
        nianji: '61'
      },
      {
        nianji: '62'
      },
      {
        nianji: '63'
      },
      {
        nianji: '64'
      },
      {
        nianji: '65'
      },
      {
        nianji: '66'
      },
      {
        nianji: '67'
      },
      {
        nianji: '68'
      },
      {
        nianji: '69'
      },
      {
        nianji: '70'
      },
      {
        nianji: '71'
      },
      {
        nianji: '72'
      },
      {
        nianji: '73'
      },
      {
        nianji: '74'
      },
      {
        nianji: '75'
      },
      {
        nianji: '76'
      },
      {
        nianji: '77'
      },
      {
        nianji: '78'
      },
      {
        nianji: '79'
      },
      {
        nianji: '80'
      },


    ],
    POST_SEX: '',
    POST_AGE: '',
    POST_QX: '',
    POST_ADD: '',
    shangwang: '',
    sbwngdian: true,
    wangdiany: true,



    modalHidden: true,
    canshu: '',
    USER_ASSETS_IDCARD: '',
    ad_img: '',
    PRIZE_ID: '',
    choujiang: true,
    openid: '',
    OPEN_ID: '',
    SHARE_OPEN_ID: '',
  },




  handleInput(e) {
    let POST_SALARY = this.validateNumber(e.detail.value)
    this.setData({
      POST_SALARY
    })
  },
validateNumber(val) {
    return val.replace(/\D/g, '')
  },




  back() {
    wx.navigateBack({
      delta: 1
    })
  },



  wangdianshagn() {

    if (this.data.POST_ADD == '') {
      wx.showToast({
        title: '请先选择县区！',
        icon: 'none',
        duration: 1500
      })
    } else {

      this.setData({
        sbwngdian: false
      })
    }



  },

  wangshang(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.wangname);

    this.setData({
      POST_QX: e.currentTarget.dataset.item.wangname,
      sbwngdian: true,

    })
  },



  xuannian() {
    this.setData({
      nianji: false
    })
  },


  nian(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.nianji);

    this.setData({
      POST_AGE: e.currentTarget.dataset.item.nianji,
      nianji: true
    })
  },


  xinbie() {
    this.setData({
      xingbie: false
    })
  },


  xin(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.xinbie);

    this.setData({
      POST_SEX: e.currentTarget.dataset.item.xinbie,
      xingbie: true,

    })
  },




  //网点选择
  wangji() {
    this.setData({
      wangdiany: false
    })
  },

  xwang(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.wangname);

    this.setData({
      POST_ADD: e.currentTarget.dataset.item.wangname,
      wangdiany: true,
      shangwang: e.currentTarget.dataset.item.wangnamea,
    })
  },




  //职位
  stnd() {
    this.setData({
      xueshen: false
    })
  },


  xsname(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.CON_VALUE);

    this.setData({
      POST_WORK: e.currentTarget.dataset.item.CON_VALUE,
      xueshen: true
    })
  },



  sihuodong() {
    wx.request({
      url: app.globalData.interface+'/shanyouhui/API_1008_getAllConfig?code=SHANGLUOWORKPOST',
      method: 'GET',
      data: {
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data.configList);
        this.setData({
          txtlist: res.data.configList,

        })
        console.log(this.data.txtlist);
      }
    })
  },



  //验证手机号
  mobileInput(e) {
    let value = e.detail.value.replace(/\D/g, '')
    this.setData({
      mobile: value,
    })
    var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (this.data.mobile.length == 0) {
      wx.showToast({
        title: '输入的手机号为空，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        mobileFormat: false,
      })
    } else if (this.data.mobile.length < 11) {

      wx.showToast({
        title: '手机号长度有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        POST_PHONE: '',
        mobileFormat: false,
      })

    } else if (!myreg.test(this.data.mobile)) {
      wx.showToast({
        title: '手机号有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        POST_PHONE: '',
        mobileFormat: false,
      })

    } else {
      this.setData({
        mobileFormat: true,
      })
    }
  },




  bouut() {
    this.setData({
      openid: app.globalData.openid,
    })

    console.log(this.data.openid);
    // if (this.data.POST_SEX == "" ||this.data.POST_AGE == "" ||this.data.POST_SALARY == "" || this.data.POST_WORK == "" ||this.data.POST_NAME == "" || this.data.STUDENT_PHONE == ""|| this.data.POST_QX == ""|| this.data.POST_ADD == "") {
      if (this.data.POST_NAME == "" || this.data.STUDENT_PHONE == "") {
      wx.showToast({
        title: '请完善信息',
        icon: 'none',
        duration: 1500
      })

    } else {
      wx.request({
        url: app.globalData.interface+'/hundredBaoJi/API_1607_addUserCouponAssets',
        method: 'POST',
        data: {
          USER_ASSETS_NAME: this.data.POST_NAME,
          USER_COUPON_PHONE: this.data.STUDENT_PHONE,
          // POST_QX: this.data.POST_QX,
          // POST_ADD: this.data.POST_ADD,
          // POST_WORK: this.data.POST_WORK,
          // POST_SALARY: this.data.POST_SALARY,
          // POST_AGE: this.data.POST_AGE,
          // POST_SEX: this.data.POST_SEX,


          
          OPEN_ID: this.data.openid, //用户OPEN_ID
          session_key: this.data.session_key,
          OPEN_UUID: this.data.jiami,
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log(res.data);
          console.log(res);

          if (res.data.result == 'success') {
            wx.showModal({
              // title: '温馨提示',
              content: res.data.data,
              success: function (res) {
                if (res.confirm) { //这里是点击了确定以后   
                  console.log('用户点击确定')
                } else { //这里是点击了取消以后
                  console.log('用户点击取消')
                }
              }
            })
          } else {
            wx.showModal({
              // title: '温馨提示',
              content: res.data.data,
              success: function (res) {
                if (res.confirm) { //这里是点击了确定以后   
                  console.log('用户点击确定')
                } else { //这里是点击了取消以后
                  console.log('用户点击取消')
                }
              }
            })
          }
        }
      })
    }
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {
      this.setData({
        openid: app.globalData.openid,
        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        session_key: app.globalData.session_key,
        CUSTOMER_ID: app.globalData.CUSTOMER_ID,
      });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {


    var that = this

    if (that.data.jiami == '' || that.data.session_key == '') {

      wx.login({
        success: function (res) {
          console.log(res);
          if (res.code) { //wx.login获取code。
            console.log(res.code);
            //发起网络请求

            wx.request({
              url: app.globalData.interface+'/post/API_1062_appGetOpenid',
              // url: 'http://192.168.3.173:8081/post/API_1062_appGetOpenid',
              method: 'GET',
              //向后端发送的数据
              data: {
                code: res.code //将code发送到后台服务器。
              },
              header: {
                "Content-Type": "application/x-www-form-urlencoded" //POST方式是这个
              },
              success: res => {
                console.log(res);
                if (res.data.result != 'success') {
                  console.log(1);
                  // wx.showToast({
                  //   title: '请获取手机号',
                  //   duration: 1000
                  // })
                } else {
                  var openid = res.data.openid;
                  app.globalData.openid = openid;

                  console.log(res.data.openid);
                  that.setData({
                    openid: res.data.openid
                  })
                  // that.scanCod()

                  that.setData({
                    phone: app.globalData.phone,
                    CUSTOMER_ID: app.globalData.CUSTOMER_ID,
                    jiami: app.globalData.jiami,
                    OPEN_ID: app.globalData.openid,
                    openid: app.globalData.openid,
                    session_key: app.globalData.session_key,
                  })
                  console.log(that.data.phone);
                  console.log(that.data.jiami);
                  console.log(that.data.openid);
                  console.log(that.data.session_key);
                }

              }
            })
          } else {
            console.log('获取用户登录态失败！' + res.errMsg)
          }
        }
      });
    } else {

      console.log('成功');
    }




    this.sihuodong()



  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  }


})